<template>
    <div>
      <span v-if="list.length === 0">暂无数据</span>
  <mu-paper v-loading="loading1" :z-depth="1" class="demo-list-wrap">
  <!-- <mu-appbar color="cyan">
    <mu-button icon slot="left">
      <mu-icon value="menu"></mu-icon>
    </mu-button>
    Inbox
    <mu-button icon slot="right">
      <mu-icon value="search"></mu-icon>
    </mu-button>
  </mu-appbar> -->
  <mu-list  v-for="item in list" :key="item.product_id" textline="three-line">
    <!-- <mu-sub-header>今天</mu-sub-header> -->
    <div @click="historybtn(item)">
      <mu-list-item   avatar :ripple="false" button>
      <mu-list-item-action>
        <mu-avatar>
          <img :src="item.product_img_url">
        </mu-avatar>
      </mu-list-item-action>
      <mu-list-item-content>
        <mu-list-item-title>{{item.product_name}}</mu-list-item-title>
        <!-- <mu-list-item-sub-title style="color: rgba(0, 0, 0, .87)">{{item.product_detail}}</mu-list-item-sub-title> -->
        <mu-list-item-sub-title>
          {{item.product_detail}}
        </mu-list-item-sub-title>
      </mu-list-item-content>
      <mu-list-item-action >
        <mu-list-item-after-text>￥{{item.product_price}}</mu-list-item-after-text>
        <mu-icon v-if="item.focusf_lag === 0 && !historyFlag" @click="Focus($event,item)" value="favorite_border"></mu-icon>
        <mu-icon v-if="item.focusf_lag === 1 && !historyFlag" @click="Focus1($event,item)" value="favorite"></mu-icon>
        <!-- <mu-checkbox color="yellow700" v-model="selects" :value="item.product_id" uncheck-icon="star_border" checked-icon="star"></mu-checkbox> -->
      </mu-list-item-action>
    </mu-list-item>
    </div>
  </mu-list>
</mu-paper>
    </div>
</template>
<script>
import { constants } from 'crypto';
export default {
    data () {
        return {
            list:[],
            selects: [],
			historyFlag: false,
            id1: '',
            loading1: false
        }
    },
    mounted () {
		this.historyFlag = this.$_global.getRouterParams(this.$router)._historyFlag
        this.id1 = JSON.parse(window.sessionStorage.userInfo).user_id
        if (this.historyFlag) {
			this.followbtn1()
        } else {
          this.followbtn()
        }
    },
    methods: {
        followbtn () {
            this.loading1 = true
            this.$axios.post('/focus',{
                uid:this.id1,
                focus: 1
                }).then(res => {
                if (res.status === 1) {
                    console.log('resdfasd', res)
                    this.list = res.database
                } else {
                    console.log(res.msg)
                }
                this.loading1 = false
            })
        },
        followbtn1 () {
            this.loading1 = true
            this.$axios.post('/historys',{
              uid:this.id1
            }).then(res => {
                if (res.status === 1) {
                    this.list = res.database
                } else {
                    console.log(res.msg)
                }
                this.loading1 = false
            })
        },
        historybtn (val) {
          console.log('val', val)
            this.$_global.selfPage('/detail', {
                productId:val.product_id
            },this.$router)
        },
        Focus (e,val) {
                e.preventDefault()
                this.loading1 = true
                this.$axios.post('/focusadd', {
                    focus: 1,
                    user_id: this.id1,
                    pruduct: val.shop_id
                }).then(res => {
                    if (res.status === 1) {
                        console.log(res.msg)
                        this.$toast.success({
                            position: 'top',
                            message: res.msg
                        });
                        this.followbtn()
                    } else {
                        console.log(res.msg)
                    }
                    this.loading1 = false
                })
            },
        Focus1 (e,val) {
            e.preventDefault()
            this.loading1 = true
            this.$axios.post('/focusadd', {
                focus: 0,
                user_id: this.id1,
                pruduct: val.shop_id
            }).then(res => {
                if (res.status === 1) {
                    console.log(res.msg)
                    this.$toast.success({
                        position: 'top',
                        message: '取消关闭成功'
                    });
                    this.followbtn()
                } else {
                    console.log(res.msg)
                }
                this.loading1 = false
            })
        }
    }
}
</script>
